﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.ViewModel;
using Hockey.Shared;

namespace Hockey.UILayer.ViewModels
{
    /// <summary>
    /// ViewModel for game info view
    /// </summary>
    public class GameInfoViewVM: NotificationObject
    {
        private IEventAggregator _events;
        private GameSettings _settings;

        /// <summary>
        /// Constructor
        /// </summary>
        public GameInfoViewVM(IEventAggregator events)
        {
            if (events == null)
                throw new ArgumentNullException("Events");
            _events = events;


            // register notifications
            _events.GetEvent<StartNewGame>().Subscribe((s) =>
                {
                    _settings = s;
                    Update();
                }, true);
        }

        #region Binding Properties

        public string GameStyle
        { get; set; }

        public string EngineLevel
        { get; set; }

        public string FirstToMove
        { get; set; }


        #endregion

        /// <summary>
        /// Updates the view
        /// </summary>
        private void Update()
        {
            // update config strings
            GameStyle = _settings.GameMode == eGameMode.ComputerGame ? "Hra s počítačem" : "Hra dvou hráčů";
            if (_settings.GameMode == eGameMode.ComputerGame)
            {
                EngineLevel = _settings.EngineLevel == eEngineLevel.Novice ? "Začátečník" : "Pokročilý";
                FirstToMove = _settings.FirstToMove == eFirstToMove.Computer ? "Počítač" : "Hráč";
            }
            else
            {
                EngineLevel = string.Empty;
                FirstToMove = string.Empty;
            }

            // notify the change
            RaisePropertyChanged("GameStyle");
            RaisePropertyChanged("EngineLevel");
            RaisePropertyChanged("FirstToMove");
        }
    }
}
